package com.liujianlei.forum_system.controller;

import com.liujianlei.forum_system.common.AppResult;
import com.liujianlei.forum_system.exception.ApplicationException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @Author 比特就业课
 * @Date 2023-05-21
 */

@Api(tags = "TestController 测试接口")
// 第一级的映射
@RequestMapping("/test")
@RestController
public class TestController {

    // API 方法描述
    @ApiOperation(value = "测试接口，打印hello")
    @GetMapping("/hello")
    public String testHello () {
        return "hello, Spring boot....";
    }


    // API 方法描述
    @ApiOperation(value = "测试接口，全局异常！")
    @GetMapping("/exception")
    public String testException() throws Exception {
        throw new Exception("这是一个Exception");
    }

    // API 方法描述
    @ApiOperation(value = "测试接口，自定义异常")
    @GetMapping("/appException")
    public String testApplicationException() {
        throw new ApplicationException("这是一个自定义的ApplicationException");
    }

    // 注意：@ApiParam 方法参数的注解，用来描述参数
    @ApiOperation(value = "测试接口3，返回 你好+传入参数")
    @GetMapping("/helloByName")
    public AppResult<String> helloByName(@ApiParam(value = "名字", required = true) String name) {
        return AppResult.success("你好：" + name);
    }

}